<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户管理</title>
<link rel="stylesheet" href="/layui/css/layui.css"></link>
<link rel="stylesheet" href="/css/css.css"></link>
<style>
	.layui-table-body .layui-table-cell{
		height:50px;
		line-height: 50px;
	}
</style>
</head>
<body>

<script type="text/html" id="switchTpl">
	<!-- 这里的 checked 的状态只是演示 -->
	<input type="checkbox" name="{{d.openid}}" value="{{d.level}}" lay-skin="switch" lay-filter="vipSwitch" lay-text="&nbsp;是&nbsp;|&nbsp;否&nbsp;" {{ d.level == 'VIP会员' ? 'checked' : '' }}>
</script>

<div style="padding: 20px">
	        <span class="layui-breadcrumb">
			  <a>首页</a>
			  <a><cite>用户管理</cite></a>
			</span>
	<div style="padding-top: 20px;">
		<div style="padding: 20px">
			<div class="layui-form">

				<div class="layui-inline">
					<label class="layui-form-label">openid：</label>
					<div class="layui-input-inline">
						<input type="text" id="s_openid"  placeholder="请输入" autocomplete="off" style="width: 400px" class="layui-input" onkeydown="if(event.keyCode==13) search()"/>
					</div>
				</div>


				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-list"  lay-submit="" onclick="search()" lay-filter="LAY-app-contlist-search">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn" ></i>
					</button>
				</div>
			</div>
		</div>
		<div>
			<table width="100%" id="userListTable" ></table>
		</div>
	</div>
</div>

<script src="/layui/layui.js"></script>
<script src="/js/jquery.js"></script>
<script src="/js/common.js"></script>
<script type="text/javascript">

    layui.use(['element','form','table'], function(){
        var form=layui.form;
        var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
        $ = layui.jquery; // 使用jquery
        table = layui.table;

        table.render({
            elem: '#userListTable'
            ,url:'/admin/user/list'
            ,cols: [[
                {type:'checkbox'}
                ,{field:'openid', width:350,title: 'openid'}
                ,{field:'userImage',align:'center', width:100,title: '用户头像',templet:formatImageName}
                ,{field:'type', width:100,title: '登录方式'}
                ,{field:'nickName', title: '用户昵称'}
                ,{field:'level', width:100,title: 'VIP会员？',templet: '#switchTpl', unresize: true}
            ]]
            ,page: true
        });

        // 监听热门操作
        form.on('switch(vipSwitch)', function(obj){
            $.post("/admin/user/updateVipState",{"openid":this.name,"vip":obj.elem.checked},function(result){
                if(result.success){
                    layer.msg("执行成功！");
                    table.reload("userListTable",{});
                }else{
                    layer.msg("执行失败，请联系管理员！");
                }
            },"json");

        });

    });


    function search(){
        var s_openid=$("#s_openid").val();
        table.reload("userListTable",{
            page:{
                curr:1
            }
            ,where:{
                openid:s_openid
            }
        })
    }



    function formatImageName(d) {
        return "<img width='50' height='50'  src='"+d.userImage+"'/>";
    }




</script>
</body>
</html>